package com.study.gank.ui.activity

import android.app.Activity
import android.app.ActivityOptions
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.widget.ImageView
import androidx.databinding.DataBindingUtil
import com.study.gank.R
import com.study.gank.databinding.ActivityImageBinding
import org.jetbrains.anko.sdk27.coroutines.onClick

/**
 * <pre>
 *     author : xxs
 *     time   : 2021/01/04
 *     desc   :
 * </pre>
 */
class ImageActivity : BaseBindingActivity<ActivityImageBinding>() {
    override fun createDataBinding(savedInstanceState: Bundle?): ActivityImageBinding {
        return DataBindingUtil.setContentView(this, R.layout.activity_image)
    }

    override fun initView() {
        mBinding.root.onClick {
            supportFinishAfterTransition()
        }
        mBinding.url = intent.getStringExtra(IMG)
    }

    companion object {
        val IMG = "img"
        fun starter(context: Context, imageView: ImageView, url: String) {
            val intent = Intent(context, ImageActivity::class.java)
            intent.putExtra(IMG, url)
            if (Build.VERSION.SDK_INT > 21) {
                context.startActivity(
                    intent,
                    ActivityOptions.makeSceneTransitionAnimation(
                        context as Activity,
                        imageView,
                        "img"
                    ).toBundle()
                )
            } else {
                context.startActivity(intent)
            }
        }
    }
}